package com.hnjme.cnec.gateway.swagger.route;

import com.hnjme.cnec.gateway.swagger.handler.ResourceHandler;
import com.hnjme.cnec.gateway.swagger.handler.SecurityHandler;
import com.hnjme.cnec.gateway.swagger.handler.UiHandler;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;

/**
 * swagger-resource端点
 *
 * @author Luo Liang
 */
@Slf4j
@Configuration
@AllArgsConstructor
public class SwaggerRouterFunction {
    private final ResourceHandler swaggerResourceHandler;
    private final SecurityHandler swaggerSecurityHandler;
    private final UiHandler swaggerUiHandler;

    @Bean
    public RouterFunction<?> routerFunction() {
        return RouterFunctions.route(
                RequestPredicates.GET("/swagger-resources")
                        .and(RequestPredicates.accept(MediaType.ALL)), swaggerResourceHandler)
                .andRoute(RequestPredicates.GET("/swagger-resources/configuration/ui")
                        .and(RequestPredicates.accept(MediaType.ALL)), swaggerUiHandler)
                .andRoute(RequestPredicates.GET("/swagger-resources/configuration/security")
                        .and(RequestPredicates.accept(MediaType.ALL)), swaggerSecurityHandler);
    }
}
